package com.flyou.mvpdemo.view;

import android.app.ProgressDialog;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.flyou.mvpdemo.R;
import com.flyou.mvpdemo.presenter.ShowViewPresenter;

public class MainActivity extends AppCompatActivity implements IStstusShow, View.OnClickListener {
    private ProgressDialog progressDialog;
    private ShowViewPresenter presenter;
    private AlertDialog.Builder alertDialog;
    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        presenter = new ShowViewPresenter(this);
        button= (Button) findViewById(R.id.button);
        button.setOnClickListener(this);
    }

    @Override
    public void showProcessBar() {
        progressDialog=ProgressDialog.show(MainActivity.this,"正在检测网络状态……",null,false,true);
    }

    @Override
    public void hideProcessBar() {
        progressDialog.dismiss();
    }

    @Override
    public void showNetError() {
        alertDialog=new AlertDialog.Builder(MainActivity.this);
        alertDialog.setTitle("网络连接异常");
        alertDialog.setNegativeButton("取消", null);
        alertDialog.setPositiveButton("确定", null);
        alertDialog.show();
    }

    @Override
    public void startActivity() {
        Toast.makeText(this, "startActivity", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onClick(View v) {
        presenter.startLoading(MainActivity.this);
    }
}
